require("../util.js");
require("../component/components.js");
require("../../jsMt/util.js");
var vm = new Vue({
    el:"#enterpriseInfo",
    data:{
        isTop:false,
        isShow:false,
        isNav:1,
        isVideo:false,
        loadFlag:false,
        enterpriseId:"", //企业职位id
        loginUid:"",  //用户id
        enterpriseInfo:{},//企业信息
        pageNumber:1,
        releaseAdvList:{},
        releaseAdvList1:[],
        releaseAdvList2:[]
    },
    mounted:function(){
        this.searchObject = this.getQueryStringArgs();
        this.enterpriseId=this.searchObject&&this.searchObject.enterpriseId;
        this.loginUid=this.searchObject&&this.searchObject.uid;
        this.getEnterpriseId();
        this.getEnterpriseReleaseAdvList();
    },
    methods:{
        //后退
        getBack:function(){
            history.go(-1);
        },
        bgimg:function(url){
            url = url?url:"";
            return {
                "background-image":'url("'+url+'"),url("")'
            }
        },
        /*获取查询字符对象*/
        getQueryStringArgs: function () {
            //取得查询字符串并去掉开头的问号
            var qs = (location.search.length > 0 ? location.search.substring(1) : ""),
                args = {},
                items = qs.length ? qs.split("&") : [],
                item = null,
                name = null,
                value = null,
                len = items.length;
            for (var i = 0; i < len; i++) {
                item = items[i].split("=");
                name = item[0];
                value = item[1];
                if (name.length) {
                    args[name] = value;
                }
            }
            return args;
        },
        //获取企业信息
        getEnterpriseId:function(){
            var that=this;
            var data={
                loginUid:that.loginUid,
                enterpriseId:that.enterpriseId
            };
            this.ajax({url:"/see/getEnterpriseId",data:data,dataType:"json",method:"post"},function(b){
                if(b.json.code==0&&b.json.data){
                    that.enterpriseInfo=b.json.data;
                    // that.goodslength=that.groupInfo.products.length;
                    // that.state=that.groupInfo.state;
                    // that.remind=that.groupInfo.remind;

                }else{
                    vm.$refs.prompt.toast("获取企业信息失败！")
                }
            });
        },
        //获取企业历史发布列表
        getEnterpriseReleaseAdvList:function(){
            var that=this;
            var data={
                pageNumber:that.pageNumber,
                enterpriseId:that.enterpriseId
            };
            this.ajax({url:"/see/getEnterpriseReleaseAdvList",data:data,dataType:"json",method:"post"},function(b){
                if(b.json.code==0&&b.json.data){
                    that.releaseAdvList=b.json.data;
                    that.releaseAdvList1=that.releaseAdvList.list;
                    if(that.releaseAdvList.pageNumber>1){
                        if(that.releaseAdvList.list.length>0) {
                            that.releaseAdvList2 = that.releaseAdvList2.concat(b.json.data.list);
                        }
                    }else{
                        that.releaseAdvList2= that.releaseAdvList1;
                    }
                    vm.loadFlag=false;
                    // lazyload();
                }else{
                    that.releaseAdvList={};
                    that.releaseAdvList1=[];
                    that.releaseAdvList2=[];
                    vm.$refs.prompt.toast("获取企业历史发布列表失败！")
                }
            });
        },
        getData:function(data){
            var dataList=data.split(" ")[0].split("-");
            return dataList[0]+"年"+dataList[1]+"月"+dataList[2]+"日";
        },
        //显示隐藏
        getIsshow:function(){
            this.isShow=!this.isShow;
        },
        getNext:function(){
            location.href="/see/companyInfo?uid="+this.loginUid+"&enterpriseId="+this.recruitInfo.enterpriseId;
        }

    }
});
//文档高度
function getDocumentTop() {
    var scrollTop = 0, bodyScrollTop = 0, documentScrollTop = 0;
    if (document.body) {
        bodyScrollTop = document.body.scrollTop;
    }
    if (document.documentElement) {
        documentScrollTop = document.documentElement.scrollTop;
    }
    scrollTop = (bodyScrollTop - documentScrollTop > 0) ? bodyScrollTop : documentScrollTop;    return scrollTop;
}
//可视窗口高度
function getWindowHeight() {
    var windowHeight = 0;
    if (document.compatMode == "CSS1Compat") {
        windowHeight = document.documentElement.clientHeight;
    } else {
        windowHeight = document.body.clientHeight;
    }
    return windowHeight;
}
//滚动条滚动高度
function getScrollHeight() {
    var scrollHeight = 0, bodyScrollHeight = 0, documentScrollHeight = 0;
    if (document.body) {
        bodyScrollHeight = document.body.scrollHeight;
    }
    if (document.documentElement) {
        documentScrollHeight = document.documentElement.scrollHeight;
    }
    scrollHeight = (bodyScrollHeight - documentScrollHeight > 0) ? bodyScrollHeight : documentScrollHeight;
    return scrollHeight;

}
window.onscroll=function(){
    if(getDocumentTop()>140){
        vm.isTop=true;
    }else{
        vm.isTop=false;
    }
    var loadFlag = vm.releaseAdvList.lastPage;
    //监听事件内容
    if(getScrollHeight()==getWindowHeight() + getDocumentTop()){
        //当滚动条到底时,这里是触发内容
        if(!loadFlag){
            vm.loadFlag=true;
            vm.pageNumber++;
            vm.getEnterpriseReleaseAdvList();
            lazyload();
        }else{
            vm.$refs.prompt.toast("没有更多了！")
        }
    }
};
function lazyload(){
    $("img.lazy").lazyload();
}
